import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
import index from './pages/index.vue'
import AboutMe from './pages/AboutMe.vue'
import Recommend from './pages/Recommend.vue'
import watchMv from './pages/watchMv.vue'

var router = new VueRouter({ // 创建路由实例对象router
    routes: [
        {
            path: '/',
            redirect: '/index'
        },
        {
            path: '/index',
            component: index,
            name: 'index',
            meta: { title: 'Mv首页' }
        },
        {
            path: '/Recommend',
            component: Recommend,
            name: 'Recommend',
            meta: { title: '推荐' }
        },
        {
            path: '/AboutMe',
            component: AboutMe,
            name: 'AboutMe',
            meta: { title: '关于我' }
        },
        {
            path: '/watchMv/:id',
            component: watchMv,
            props:true,
            name: 'watchMv',
            meta: { title: "网易mv"}
        }
    ]
})


//导航守卫，用于动态更改页面标题
router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title
    }
    next()
})

export default router     // 暴露路由对象属性
